package cn.hzking.gjmall.utils;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import java.util.Iterator;

import cn.hzking.gjmall.activitys.second.NYuanGoodListActivity;
import cn.hzking.gjmall.activitys.second.NormalGoodListActivity;
import cn.hzking.gjmall.activitys.second.QgGoodListActiivty;
import cn.hzking.gjmall.activitys.second.SearchGoodListActivity;
import cn.hzking.gjmall.activitys.second.WebGoodDetailActivity;

/**
 * Created by Administrator on 2018/2/24.
 */

/*
* url : "/shop/activity/activity.html?id=175"     活动
Url : "/shop/iteLtNo.html?categoryId=185"     商品列表 （没有排序功能）
url : "/shop/itemQg.html?qgId=71"       抢购商品列表
url : "/shop/itemDetail.html?itemId=686"   商品详情

/shop/kjgItemList  跨境偶商品列表(path)
/shop/itemList  普通商品列表
id=175(qury)
*
* */
//scheme://authority/path1/path2/path3?id = 1&name = mingming&old#fragment
public class UriMatch {
    private final String URIHOST = "gjmall://goods";
    private Uri mUri;
    private Activity context;
    private Iterator<String> queryItearator;
    private final String ACTIVITYPATH ="/shop/activity/activity.html";//跳转活动页的路径
    private final String NOSORTGOODPATH = "/shop/iteLtNo.html";//没有排序商品列表页(普通的列表页)
    private final String COMMONGOODPATH = "/shop/itemList.htm";//搜索出来的列表页
    private final String QGGOODPATH = "/shop/itemQg.html";//抢购商品列表页
    private final String KJGOODPATH = "/shop/kjgItemList";//跨境商品列表页
    private final String GOODDETAIL = "/shop/itemDetail.html";//商品详情
    private final String SECKILLPATH = "/shop/seckllList.html";//秒杀列表
    private final String NYUANXUAN = "/shop/nselectList.htm";//n元选列表页
    private final String COUPON ="/shop/ajax/couponDetail/getCoupon.json";;//优惠券列表页
    private final String COUPONPACkAGE = "/shop/ajax/couponDetail/getCouponPackage.json";//优惠券礼包(活动页面)
    private final String DIANZHUZHUANXIANG = "/shop/dzVip.htm";//店主专享(活动页面)
    private final String WEEKNEW = "/shop/newItem.htm";//本周上新(活动页面)
    private final String SHOPVIP = "/shop/dzVip.htm";//店主专享(活动页面)

    private final String SECKDETAIL = "/shop/seckllDetail.htm";

    public UriMatch( Activity activity,String uri) {
        try {
            String totleUri = URIHOST + uri;
           mUri = Uri.parse(totleUri);
        } catch (Exception e) {
            e.printStackTrace();
            UIUtils.showToastShort(context, "未知错误");
        }
        this.context = activity;
    }
    public  void  match(){
        String authority = mUri.getAuthority();
        String path = mUri.getPath(); //路径
        String query = mUri.getQuery(); //查询参数
        if(ACTIVITYPATH.equals(path) || WEEKNEW.equals(path) || SHOPVIP.equals(path) || COUPONPACkAGE.equals(path) ||DIANZHUZHUANXIANG.equals(path)){//跳转活动页的路径
            String id = mUri.getQueryParameter("id");
            UIUtils.showToast(context,"活动页面", Toast.LENGTH_SHORT);
        }
        else if(NOSORTGOODPATH.equals(path)){//普通列表页
            String categoryId = mUri.getQueryParameter("categoryId");
            Intent intent = new Intent(context, NormalGoodListActivity.class);
            intent.putExtra("categoryId",categoryId);
            context.startActivity(intent);
        }
        else if(COMMONGOODPATH.equals(path)){//搜索商品列表页
            String categoryId = mUri.getQueryParameter("categoryId");
            Intent intent = new Intent(context, SearchGoodListActivity.class);
            intent.putExtra("keyword",categoryId);
            context.startActivity(intent);

        }else if(QGGOODPATH.equals(path)){//抢购商品列表页
            String qgId = mUri.getQueryParameter("qgId");
            Intent intent = new Intent(context, QgGoodListActiivty.class);
            intent.putExtra("qgId",qgId);
            context.startActivity(intent);


        }else if(KJGOODPATH.equals(path)){//跨境商品列表

        }else if(GOODDETAIL.equals(path)){//商品详情
            String itemId = mUri.getQueryParameter("itemId");
            WebGoodDetailActivity.startActivity(context,WebGoodDetailActivity.NOMAL,itemId,"","","");


        }else if(SECKILLPATH.equals(path)){//秒杀列表
          /*  String secillActivityId = mUri.getQueryParameter("msId");
            Intent intent = new Intent(context, SeckillGoodListActivity.class);
            intent.putExtra("secillActivityId",secillActivityId);
            context.startActivity(intent);*/
          UIUtils.showToast(context,"后台数据结构不正确",Toast.LENGTH_SHORT);

        }else if(NYUANXUAN.equals(path)) {//N元选列表
            String nsId = mUri.getQueryParameter("nsId");
            Intent intent = new Intent(context, NYuanGoodListActivity.class);
            intent.putExtra("nsId", nsId);
            context.startActivity(intent);
        }
        else if(SECKDETAIL.equals(path)){//跳转秒杀商品详情页
            String itemId = mUri.getQueryParameter("itemId");
            String msId = mUri.getQueryParameter("msId");
            WebGoodDetailActivity.startActivity(context,WebGoodDetailActivity.SEACK,itemId,msId,"","");
          //  UIUtils.showToast(context,"秒杀商品详情页",Toast.LENGTH_SHORT);


        }
    }
}
